<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />

        <!-- <el-select v-model="type" placeholder="選擇充值方式" size="large" style="width: 240px" class="mr10 mb10">

          <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select> -->
        <el-select v-model="status" placeholder="選擇狀態" size="large" style="width: 240px" class="mr10 mb10">
          <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-input v-model="order_no" style="width: 280px" placeholder="搜尋訂單號..." :prefix-icon="Search" class="search mr10 mb10" />

        <el-input v-model="trade_no" style="width: 280px" placeholder="搜尋三方平臺訂單號..." :prefix-icon="Search" class="search mr10 mb10" />


      </div>
      <div class="noshrink mb10">
        <!-- 查詢按鈕，點擊時調用 getRechargeList 方法 -->
        <el-button class="btn2" @click="getRechargeList()">查詢</el-button>
        <!-- 重置按鈕，點擊時調用 reset 方法 -->
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="id" label="序號" width="100" sortable />
          <el-table-column prop="user" label="用戶訊息" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.user.id)">{{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="type_text" label="充值方式" width="150" />
          <el-table-column prop="money" label="充值金額" width="150" />
          <el-table-column prop="order_no" label="訂單號" min-width="200">
          </el-table-column>
          <el-table-column prop="trade_no" label="三方平臺訂單號" sortable min-width="200" />
          <el-table-column prop="status" label="狀態" sortable width="150">
            <template #default="scope">
              <div class="yellow" v-if="scope.row.status != 1 && scope.row.status != 0">處理中</div>
              <div class="blue" v-if="scope.row.status == 1">已收款</div>
              <div class="red" v-if="scope.row.status == 0">未支付</div>

            </template>
          </el-table-column>

          <el-table-column prop="created_at" label="創建時間" sortable min-width="200" />
          <el-table-column prop="updated_at" label="更新時間" sortable min-width="200" />
          <!-- <el-table-column prop="address" label="操作" width="150" fixed="right">
            <template #default>
              <div class=" pointer" @click="edit(2)">重新鏈接API</div>
            </template>
          </el-table-column> -->

        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
    <el-dialog v-model="dialogTableVisible" title="本月紅利排行榜">
      <div class="plr20 justify-between ptb20">
        <div>
          <el-time-picker v-model="value2" placeholder="開始時間" />
          <span class="plr10">-</span>
          <el-time-picker v-model="value2" placeholder="結束時間" />
        </div>
        <div>
          <el-button class="btn2">查詢</el-button>
          <el-button class="btn1">重置</el-button>
        </div>

      </div>
      <el-table :data="tableData" cell-class-name="dialogtbcell" header-cell-class-name="dialoghdcell">
        <el-table-column property="name" label="用戶訊息" min-width="200" />
        <el-table-column property="name" label="用戶昵稱" min-width="200" />
        <el-table-column property="address" label="用戶頭像" width="200">
          <template #default>
            <el-avatar shape="square" :size="50" :fit="'cover'" :src="url" />
          </template>

        </el-table-column>
        <el-table-column property="address" label="禮物金額" width="200" />

      </el-table>
      <div class="  plr20 justify-between mt20">
        <div style="flex:1;" class="clr3c4 bold">總共10條</div>
        <div>小計(元): <span class="ft46 clr3c4 ml10">445587</span> </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { rechargeList } from '@/api/finance.js'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getRechargeList()
})

// 充值记录
const getRechargeList = () => {
  rechargeList({
    page: currentPage.value,
    uid: uid.value,
    type: type.value,
    status: status.value,
    order_no: order_no.value,
    trade_no: trade_no.value
  }).then((res) => {
    console.log('充值记录列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const reset = () => {
  uid.value = ''
  type.value = ''
  status.value = ''
  order_no.value = ''
  trade_no.value = ''
  getRechargeList()
}
const uid = ref('')
const type = ref('')
const status = ref('')
const order_no = ref('')
const trade_no = ref('')

const dialogTableVisible = ref(false)
const typeOptions = [
  {
    label: 'paypal',
    value: '1'
  },
  {
    label: '蘋果',
    value: '2'
  },
  {
    label: 'google',
    value: '3'
  },
]
const statusOptions = [
  {
    label: '未支付',
    value: '0'
  },
  {
    label: '已收款',
    value: '1'
  },
]
const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'addNotice' })
}
const edit = (type) => {
  router.push({ path: 'signEdit' })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
 